﻿using BussinessObject.ObjectTwo;
using Class_Entity.ObjectTwo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectHK3.App_Code;

namespace ProjectHK3.Object_One
{
    public partial class DistanceDetail : System.Web.UI.Page
    {
        Distances dis = new Distances();
        B_LoadDrop bl = new B_LoadDrop();
        B_Search ex = new B_Search();
        B_Update fx = new B_Update();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                load();
            }
        }
        public void load()
        {
            DropDownList1.DataSource = bl.Bran();
            DropDownList1.DataTextField = "BRANCH_NAME";
            DropDownList1.DataValueField = "BRANCH_ID";
            DropDownList1.DataBind();

            DropDownList2.DataSource = bl.Bran();
            DropDownList2.DataTextField = "BRANCH_NAME";
            DropDownList2.DataValueField = "BRANCH_ID";
            DropDownList2.DataBind();

            int tam = int.Parse(Session["Distances"].ToString());
            dis = ex.loadDistance(tam);

            TextBox1.Text = dis.KM.ToString();

            DropDownList1.SelectedValue = dis.BRANCH_ID_FROM.ToString();
            DropDownList2.SelectedValue = dis.BRANCH_ID_TO.ToString();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int tam = int.Parse(Session["Distances"].ToString());
            dis.DISTANCE_ID = int.Parse(Session["Distances"].ToString());
            dis.BRANCH_ID_FROM =int.Parse( DropDownList1.SelectedValue.ToString());
            dis.BRANCH_ID_TO =int.Parse(DropDownList2.SelectedValue.ToString());
            dis.KM =float.Parse( TextBox1.Text);
            if (fx.updateDistance(dis) == true)
            {
                Alert.Show("Update Successful");
                load();
            }
            else
            {
                Alert.Show("false");
                load();
            }
            ;
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            DropDownList1.SelectedIndex = 0;
            DropDownList2.SelectedIndex = 0;
            TextBox1.Text = "";
            TextBox1.Focus();
        }
    }
}